﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Abp.Dependency;
using Abp.Domain.Repositories;
using Abp.Domain.Uow;
using Abp.Events.Bus.Entities;
using Abp.Events.Bus.Handlers;
using Abp.RemoteEventBus;
using Abp.Runtime.Caching;
using Castle.Core.Logging;
using FwProject.Comm;
using FwProject.Core.SettlementInfoModel;
using FwProject.PrePaymentInfo;

namespace FwProject.EventHandle
{
    public class ReceiptInfoHandle : IEventHandler<EntityChangedEventData<ReceiptInfoModel>>, ITransientDependency
    {
       
        public readonly ICacheManager _catchmanager;
        public IRemoteEventBus remoteEventBus { get; set; }//缓存对象
        public ILogger _logger { get; set; }
        public ReceiptInfoHandle(ICacheManager catchmanager, IRepository<ReceiptInfoBySettlementModel, Guid> repositoryReceiptInfoBySettlementModel,
            IRepository<SettlementInfo, Guid> repositorySettlementInfo)
        {
            _catchmanager = catchmanager;
            remoteEventBus = NullRemoteEventBus.Instance;
           
            _logger = NullLogger.Instance;
        }
        /// <summary>
        /// 删除缓存
        /// </summary>
        /// <param name="eventData">Event data.</param>
        [UnitOfWork]
        public void HandleEvent(EntityChangedEventData<ReceiptInfoModel> eventData)
        {
            ICache cache = _catchmanager.GetCache(nameof(ReceiptInfoModel));
            cache.Remove("list");

            if (eventData.Entity.PaymentState == PaymentState.已缴款)
            {
                var catcheventDate = new RemoteEventData(RemoteTypeHelp.TypeReceiptInfoModelBySeletlmentInfo)
                {
                    Data = { [RemoteTypeHelp.MODELID] = eventData.Entity.Id }
                };
                remoteEventBus.Publish(RemoteTypeHelp.TopicReceiptInfoModelBySeletlmentInfo, catcheventDate);
            }

        }
    }
}
